<template>
  <view class="register-wrap">
	<view class="topVue">
		<view class="status"></view>
		<view class="navVue">
			<view style="width: 150rpx;">
				<image src="../../static/imgs/back.png" style="width: 36rpx; height: 36rpx;" @click="backFun"></image>
			</view>
			<view class="nav-title">{{ $t("注册账号") }}</view>
			<view class="changeLanBtn"></view>	
		</view>
	</view>
	<view class="place"></view>  
	  
    <!-- <view class="title">{{ $t("注册账号") }}</view>
    <view class="info">{{ $t("注册一个新账号") }}</view> -->
    <view class="form-box">
      <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
        <u-form-item label="" prop="phone" borderBottom ref="item1">
          <u--input
            :placeholder="$t('请输入手机号')"
            v-model="form.phone"
            border="none"
          ></u--input>
        </u-form-item>
        <u-form-item label="" prop="email" borderBottom ref="item1">
          <u--input
            :placeholder="$t('请输入邮箱')"
            v-model="form.email"
            border="none"
          ></u--input>
        </u-form-item>
        <u-form-item label="" prop="verificationCode" borderBottom ref="item1">
          <u--input
            :maxlength="maxlen"
            class="verificationCode-input"
            :placeholder="$t('请输入验证码')"
            v-model="form.verificationCode"
            border="none"
          ></u--input>
          <u-button class="verificationCode-btn" @click="postCode">{{
            $t("邮件验证")
          }}</u-button>
        </u-form-item>
        <u-form-item label="" prop="parentName" borderBottom ref="item1">
          <u--input
            :placeholder="$t('请输入邀请码')"
            v-model="form.parentName"
            border="none"
          ></u--input>
        </u-form-item>
        <u-form-item label="" prop="pwd" borderBottom ref="item1">
          <u--input
            :maxlength="maxlength"
            :placeholder="$t('请输入登录密码')"
            v-model="form.pwd"
            border="none"
          ></u--input>
        </u-form-item>
        <u-form-item label="" prop="confirmPwd" borderBottom ref="item1">
          <u--input
            :maxlength="maxlength"
            :placeholder="$t('请确认登录密码')"
            v-model="form.confirmPwd"
            border="none"
          ></u--input>
        </u-form-item>
        <u-form-item label="" prop="transactionPwd" borderBottom ref="item1">
          <u--input
            :maxlength="maxlength"
            :placeholder="$t('请输入交易密码')"
            v-model="form.transactionPwd"
            border="none"
          ></u--input>
        </u-form-item>
        <u-form-item
          label=""
          prop="confirmTransactionPwd"
          borderBottom
          ref="item1"
        >
          <u--input
            :maxlength="maxlength"
            :placeholder="$t('请确认交易密码')"
            v-model="form.confirmTransactionPwd"
            border="none"
          ></u--input>
        </u-form-item>
      </u--form>
      <view class="btn-box">
        <u-button @click="submit" class="submit-btn">{{ $t("注册") }}</u-button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      maxlen: 6,
      maxlength: 16,
      form: {
        phone: "",
        email: "",
        verificationCode: "",
        parentName: "",
        pwd: "",
        confirmPwd: "",
        transactionPwd: "",
        confirmTransactionPwd: "",
      },
      // rules: {
      // 	phone: {
      // 		required: true,
      // 		message: this.$t("请输入手机号"),
      // 		trigger: ["blur", "change"],
      // 	},
      // 	verificationCode: {
      // 		required: true,
      // 		message: this.$t("请输入验证码"),
      // 		trigger: ["blur", "change"],
      // 	},
      // 	parentName: {
      // 		required: true,
      // 		message: this.$t("请输入验证码"),
      // 		trigger: ["blur", "change"],
      // 	},
      // 	pwd: {
      // 		required: true,
      // 		message: this.$t("请输入登录密码"),
      // 		trigger: ["blur", "change"],
      // 	},
      // 	confirmPwd: {
      // 		required: true,
      // 		message: this.$t("请确认登录密码"),
      // 		trigger: ["blur", "change"],
      // 	},
      // 	transactionPwd: {
      // 		required: true,
      // 		message: this.$t("请输入交易密码"),
      // 		trigger: ["blur", "change"],
      // 	},
      // 	confirmTransactionPwd: {
      // 		required: true,
      // 		message: this.$t("请确认交易密码"),
      // 		trigger: ["blur", "change"],
      // 	},
      // },
    };
  },
  computed: {
    rules() {
      return {
        phone: {
          required: true,
          message: this.$t("请输入手机号"),
          trigger: ["blur", "change"],
        },
        email: {
          required: true,
          message: this.$t("请输入邮箱"),
          trigger: ["blur", "change"],
        },
        verificationCode: {
          required: true,
          message: this.$t("请输入验证码"),
          trigger: ["blur", "change"],
        },
        parentName: {
          required: true,
          message: this.$t("请输入验证码"),
          trigger: ["blur", "change"],
        },
        pwd: {
          required: true,
          message: this.$t("请输入登录密码"),
          trigger: ["blur", "change"],
        },
        confirmPwd: {
          required: true,
          message: this.$t("请确认登录密码"),
          trigger: ["blur", "change"],
        },
        transactionPwd: {
          required: true,
          message: this.$t("请输入交易密码"),
          trigger: ["blur", "change"],
        },
        confirmTransactionPwd: {
          required: true,
          message: this.$t("请确认交易密码"),
          trigger: ["blur", "change"],
        },
      };
    },
  },
  methods: {
    postCode() {
      if (!this.form.email) {
        uni.$u.toast(this.$t("请先输入邮箱"));
        return;
      }
      this.$http
        .post(`/ajax/sendCode?phoneEmail=${this.form.email}`)
        .then((res) => {
          console.log(res, 1234);
        })
        .catch((err) => {
          console.error(err);
        });
    },
	backFun(){
		uni.navigateBack({
			delta: 1
		})
	},
    submit() {
      this.$refs.uForm
        .validate()
        .then((res) => {
          if (this.form.pwd !== this.form.confirmPwd) {
            uni.$u.toast(this.$t("两次密码不一致，请重新输入确认登录密码"));
            return;
          }
          if (this.form.transactionPwd !== this.form.confirmTransactionPwd) {
            uni.$u.toast(this.$t("两次密码不一致，请重新输入确认交易密码"));
            return;
          }
          this.$http
            .post(
              `/front/register?name=${this.form.phone}&email=${this.form.email}&pwd=${this.form.pwd}&tradePwd=${this.form.transactionPwd}&parentName=${this.form.parentName}&code=${this.form.verificationCode}`
            )
            .then((res) => {
              if (res.code === 0) {
                uni.$u.toast(this.$t("注册成功"));
                uni.navigateTo({
                  url: "/pages/login/login",
                });
              }
            })
            .catch((err) => {
              console.error(err);
            });
        })
        .catch((errors) => {
          uni.$u.toast(this.$t("校验失败"));
        });
    },
  },
};
</script>

<style lang="scss">
.register-wrap {
  width: 100%;
  height: 100vh;
  background: url("../../static/imgs/bg.png") no-repeat;
  background-size: 100% 100%;
  box-sizing: border-box;
  position: fixed;
  .topVue {
  	width: 100%;
  	position: absolute;
  	left: 0;
  	top: 0;
  	z-index: 99;
  	.status {
  		width: 100%;
  		height: var(--status-bar-height);
  	}
  	.navVue {
  		width: 100%;
  		height: 92rpx;
  		background: linear-gradient(to right, #FFFBFF, #FFE7F4);
  		display: flex;
  		justify-content: space-between;
  		align-items: center;
  		box-sizing: border-box;
  		padding: 0 30rpx;
  		.nav-title {
  			width: 420rpx;
  			height: 92rpx;
  			font-size: 36rpx;
  			color: #04094C;
  			text-align: center;
  			line-height: 92rpx;
  		}
  		.changeLanBtn {
  		  width: 150rpx;
  		  color: #333;
  		}
  	}
  }
  .place {
  	height: calc(var(--status-bar-height) + 122rpx);
  }

  .title {
    width: 100%;
    height: 48rpx;
    font-size: $uni-font-size-36;
    font-family: PingFang SC;
    font-weight: bold;
    color: $uni-text-color-inverse;
    padding-top: 136rpx;
    padding-bottom: 33rpx;
  }

  .info {
    width: 100%;
    height: 32rpx;
    font-size: $uni-font-size-32;
    font-family: PingFang SC;
    font-weight: 400;
    color: $uni-text-color-grey;
    margin-bottom: 100rpx;
  }

  .btn-box {
    width: 100%;
    height: 90rpx;
    box-sizing: border-box;
    padding: 0 25rpx;
    margin-top: 82rpx;
  }

  .u-button {
    width: 100%;
    height: 100%;
    background: #D55B94;
    border-radius: 20rpx;
    color: $uni-bg-color;
    font-size: $uni-font-size-30;
    font-family: PingFang SC;
    font-weight: 400;
    border: none;
  }

  .form-box {
    width: 690rpx;
	margin: 0 auto;
    .u-form-item {
      width: 100%;
      height: 90rpx;
      margin-bottom: 30rpx;
      display: flex;
      justify-content: space-between;

      /deep/ .u-line {
        display: none;
      }

      /deep/ .u-input {
        background: #fff;
      }

      /deep/ .u-form-item__body,
      /deep/ .u-form-item__body__right__content__slot,
      /deep/ .u-input,
      /deep/ .u-input__content,
      /deep/ .u-input__content__field-wrapper,
      /deep/ .u-input__content__field-wrapper__field,
      /deep/ .uni-input-input {
        height: 100%;
        padding: 0;
      }

      /deep/ .uni-input-input {
        padding: 0 25rpx;
        box-sizing: border-box;
        font-size: $uni-font-size-26;
        font-family: PingFang SC;
        font-weight: 300;
        color: $uni-text-color-grey;
        border-radius: 20rpx;
      }

      /deep/ .uni-input-placeholder {
        padding: 0 27rpx;
      }

      .verificationCode-btn {
        width: 226rpx;
        margin-left: 20rpx;
		background: #D55B94;
      }

      .verificationCode-input {
        width: 354rpx;
      }
    }
  }
}
</style>
